const app = getApp()
const netRequest = require("../../utils/requestUtil.js");

var WxParse = require('../wxParse/wxParse.js')

Page({
  data: {
    title: "title",
    cover: "",
    poster: '',
    name: '青云志',
    author: '许巍',
    src: '',
    isPlaying: false,
    playStatus: "播放"
  },
  //事件处理函数
  bindViewTap: function () {

  },
  onLoad: function (params) {
    var self = this;

    var postId = params.postId;
    var title = params.title;
    var thumbUrl = params.cover;

    wx.setNavigationBarTitle({
      title: title
    })
    self.setData({ title: title, poster: thumbUrl });

    var videoHtml = '<video style="width:100%;height:300px;z-index:999;" src="http://120.198.248.207/cache/www.w3school.com.cn/i/movie.ogg?ich_args2=1296-15203301026691_2d3132addc0a0b89891d9b631ddde223_10001002_9c89662fd0caf4d79533518939a83798_ba2c8222e2e43cbcf7594965215cb749" controls="controls">your browser does not support the video tag</video>';

    netRequest({
      url: "/article/content",
      data: { postId: postId },
      success: function (res) {
        console.log(res.postContent);
        WxParse.wxParse('article', 'html', "<b style='padding-top:80px;'>" + (res.postContent ? res.postContent.content : '') + "</b>" + videoHtml, self, 5);
      },
      fail: function () { },
      complete: function () { }

    });

  },

  onReady: function (e) {
    // 使用 wx.createAudioContext 获取 audio 上下文 context
    this.audioCtx = wx.createAudioContext('myAudio')
  },

  togglePlay: function () {
    if (this.data.isPlaying) {
      this.audioPause();
    } else {
      this.audioPlay();
    }
  },

  audioPlay: function () {
    wx.playBackgroundAudio({
      //播放地址
      dataUrl: 'http://sc1.111ttt.com/2016/1/09/28/202280605509.mp3',
      //title 音乐名字
      title: '青云志',
      //图片地址
      coverImgUrl: 'http://r1.ykimg.com/050E0000576B75F667BC3C136B06E4E7'
    })

    this.setData({ isPlaying: true, playStatus: "暂停" });
  },
  audioPause: function () {
    // this.audioCtx.pause()
    wx.pauseBackgroundAudio();
    this.setData({ isPlaying: false, playStatus: "播放" });
  }
})
